package com.example.demo.线程池;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @description:
 * @projectName:demo
 * @see:线程
 * @author:袁成龙
 * @createTime:2020/10/6 19:41
 * @version:1.0
 */
public class TestXianChengChi {

    public static void main(String[] args) {
        ArrayBlockingQueue<Runnable> queue = new ArrayBlockingQueue(2);

        //队列执行多的得处理方式
        LinkedBlockingQueue<Runnable> runnables = new LinkedBlockingQueue<>();
        MyRejectHeader myRejectHeader = new MyRejectHeader(runnables);


        //最大存活时间,除去执行的线程之外的
        ThreadPoolExecutor executor = new ThreadPoolExecutor
                (1, 2, 20, TimeUnit.SECONDS, queue,myRejectHeader);
        for (int i = 0; i <10 ; i++) {
            //创建线程池
            executor.execute(new TestThreadPool());
        }
        //去出任务运行  然后运行
        Runnable poll = runnables.poll();
        poll.run();
        //运行完毕执行停止
        executor.shutdown();
    }

}